package com.guo.hui.controller;

import com.alibaba.fastjson.JSONObject;
import com.guo.hui.common.ApiResult;
import com.guo.hui.enity.User;
import com.guo.hui.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/user")
    public String user(){
        return "/system/user/user";
    }

    @ResponseBody
    @RequestMapping(value = "/getUserList")
    public String getUserList(@RequestBody  String param){
        List<User> list =  userService.selectUserList(param);
        ApiResult result = new ApiResult(200,"",list);
        return JSONObject.toJSONString(result);
    }

    @ResponseBody
    @RequestMapping(value = "/saveUser")
    public String saveUser(@RequestBody String param){
        User user = JSONObject.parseObject(param,User.class);
        userService.saveUser(user);
        return "world！";
    }

    @ResponseBody
    @RequestMapping(value = "/deleteUser")
    public String deleteUser(String name){
        return name + "world！";
    }

}
